﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Collections;
using SAC.Helper;
using DAL;
using System.Web;

namespace BLL
{
    public class BLLRole
    {
        ArrayList list = new ArrayList();
        StringBuilder sb = new StringBuilder();

        //DALData da = new DALData();

        public ArrayList SelectSGLRDAY(string date, string[] point, out string errMsg)
        {
            return DAL.DALEeds.RetSGLRDAY(date, point, out errMsg);
        }

        public bool SaveSGLRDAY(string[] sapoint, string[] val, string date, out string errMsg)
        {
            return DAL.DALEeds.SaveSGLRDAY(sapoint, val, date, out errMsg);
        }

        public ArrayList SelectSGLRBZ(string date, string[] point, string BZ, out string errMsg)
        {
            return DAL.DALEeds.RetSGLRBZ(date, point, BZ, out errMsg);
        }

        public bool SaveSGLRBZ(string[] arrpoint, string[] val, string date, string BZ, out string errMsg)
        {
            return DAL.DALEeds.SaveSGLRBZ(arrpoint, val, date, BZ, out errMsg);
        }

        public string SelectBZ(string TimeBZ, out string errMsg)
        {
            return DAL.DALEeds.RetBZ(TimeBZ, out errMsg);
        }


        public string RetQTJL(string date, string JZ, out string errMsg)
        {
            string[] jl1 = null;
            string[] jl2 = null;
            string[] jl3 = null;
            string[] val = null;
            ArrayList list1 = new ArrayList();
            ArrayList list2 = new ArrayList();

            list1 = DAL.DALEeds.RetSBJL(date, JZ, out errMsg);

            jl1 = (string[])list1[0];
            jl2 = (string[])list1[1];
            jl3 = (string[])list1[2];

            list2 = DAL.DALEeds.RetSBNM(jl3, out errMsg);

            val = (string[])list2[0];

            sb.AppendFormat("<tr style='width: 80%;' bgcolor='#CFE6FC'><td height='18' colspan='4' align='center'  style='width:10' align='center'>#{0}机</td></tr>", JZ);
            sb.Append("<tr style='width: 80%;' bgcolor='#CFE6FC'>");
            sb.Append("<td style='width: 5%;'><div align='center'/>序号</td>");
            sb.Append("<td style='width: 35%;'><div align='center'/>设备名称</td>");
            sb.Append("<td style='width: 30%;'><div align='center'/>启动时间</td>");
            sb.Append("<td style='width: 30%;'><div align='center'/>停止时间</td>");
            sb.Append("</tr>");

            if (jl1 != null || jl2 != null)
            {
                for (int i = 0; i < val.Length; i++)
                {
                    if (val[i] != "")
                    {
                        sb.Append("<tr style='width: 80%;' bgcolor='#FFFFFF'>");
                        sb.AppendFormat("<td style='width: 5%;'><div align='center'/>{0}</td>", (i + 1).ToString());
                        sb.AppendFormat("<td style='width: 35%;'><div align='center'/>{0}</td>", val[i]);
                        if (jl1[i] == "")
                        {
                            sb.Append("<td style='width: 35%;'><div align='center'/> - </td>");
                        }
                        else
                        {
                            sb.AppendFormat("<td style='width: 35%;'><div align='center'/>{0}</td>", jl1[i]);
                        }
                        if (jl2[i] == "")
                        {
                            sb.Append("<td style='width: 35%;'><div align='center'/>{0}</td>");
                        }
                        else
                        {
                            sb.AppendFormat("<td style='width: 35%;'><div align='center'/>{0}</td>", jl2[i]);
                        }
                        sb.Append("</tr>");
                    }
                }
            }
            else
            {
                sb.Append("没有查询到结果...");
                return sb.ToString();
            }

            return sb.ToString();

        }

        public string RetDB2conn()
        {
            //string conn = "DATABASE=" + SAC.Helper.IniHelper.ReadIniData("RelationDBbase", "DBName", null) + ";Server=" + IniHelper.ReadIniData("RelationDBbase", "DBIP", null) + ";UID=" + IniHelper.ReadIniData("RelationDBbase", "DBUser", null) + "; PWD=" + SAC.Helper.IniHelper.ReadIniData("RelationDBbase", "DBPwd", null) + "";
            string conn = "Provider=IBMDADB2;Data Source= " + IniHelper.ReadIniData("RelationDBbase", "DBName", null) + ";User ID=" + IniHelper.ReadIniData("RelationDBbase", "DBUser", null) + ";Password=" + IniHelper.ReadIniData("RelationDBbase", "DBPwd", null) + ";Default Collection =alfm01;Default Schema=Schema";
            return conn;
        }


        //public string RetDB2conn()
        //{
        //    string conn = "DATABASE=" + SAC.Helper.IniHelper.ReadIniData("RelationDBbase", "DBName", null) + ";UID=" + SAC.Helper.IniHelper.ReadIniData("RelationDBbase", "DBName", null) + "; PWD=" + SAC.Helper.IniHelper.ReadIniData("RelationDBbase", "DBPwd", null) + "";
        //    return conn;
        //}

        public bool upMenu(string sql, out string message)
        {
            DAL.DALRole dal = new DALRole();
            return dal.upMenu(sql, out message);
        }
    }
}
